package Q821

import java.util.Arrays


//字符的最短距离
class Solution {
    fun shortestToChar(s: String, c: Char): IntArray {
        val ch = s.toCharArray()
        val ans = IntArray(ch.size)
        Arrays.fill(ans, ch.size + 5)
        for (i in ch.indices) {
            var j = i
            while (j >= 0 && ch[j] != c) {
                j--
            }
            if (j >= 0) {
                ans[i] = i - j
            }
            j = i
            while (j < ch.size && ch[j] != c) {
                j++
            }
            if (j < ch.size) {
                ans[i] = Math.min(ans[i], j - i)
            }
        }
        return ans
    }
}